class Counter {
    private Integer count = 0;
    private Object lock = new Object();

    public void increment() {
        synchronized (this) {
            count++;
        }
    }

    public int getCount() {
        return count;
    }
}


class MyThread extends Thread {
    Counter counter;
    int t;
    public MyThread(Counter counter, int t) {
        this.counter = counter;
        this.t = t;
    }
    @Override
    public void run() {
        for (int i = 0; i < 1000; i++) {
            counter.increment();
            System.out.println("t" + t + ": " + counter.getCount());
        }
    }
}

public class Solution {
    public static void main(String[] args) throws InterruptedException {
        Counter counter = new Counter();

//        Thread t1 = new Thread(() -> {
//            for (int i = 0; i < 10000; i++) {
//                counter.increment();
//            }
//        });
//
//        Thread t2 = new Thread(() -> {
//            for (int i = 0; i < 10000; i++) {
//                counter.increment();
//            }
//        });
//
//        Thread t3 = new Thread(() -> {
//            for (int i = 0; i < 10000; i++) {
//                counter.increment();
//            }
//        });

        MyThread t1 = new MyThread(counter, 1);
        MyThread t2 = new MyThread(counter, 2);
        MyThread t3 = new MyThread(counter, 3);

        t1.start();
        t2.start();
        t3.start();

        t1.join();
        t2.join();
        t3.join();

        System.out.println(counter.getCount());
    }
}
